/**
 * Description: 区域管理Api
 *
 * Created by hrx on 2023/10/16
 */
import service, {IResponseArrayDto, IResponseDto} from "@/utils/ajax"
import type {IBaseQueryDataListParams} from "@/api/index"
import {AxiosResponse} from "axios"

export interface queryRegionListParam {
  id?: number,
  regionName?: string,
  merchantCode: string
}

export interface regionDetailDTO {
  id: number,
  regionLevelGroupName?: string,
  regionInfoVOList?: Array<regionInfoDTO>
}

export interface regionInfoDTO {
  id?: number,
  regionName?: string,
  regionId?: number,
  parentId?: number,
  regionRemark?: string,
  regionClassify?: number,
  subId?: Array<number>,
  children?: Array<regionInfoDTO>,
}

export interface delRegionParam {
  id?: number,
  regionClassify?: number
}

export interface queryPointParam {
  regionId: number
}

export interface pointDTO {
  id?: number,
  positionName?: string,
  remark?: string,
  relevanceDeviceName?: string,
  relevanceDeviceCount?: number,
  createTime?: string,
  regionId?: number
}

// 获取区域数据
export function getRegionListDataApi(data: queryRegionListParam): Promise<AxiosResponse<IResponseDto<Array<regionDetailDTO>>>> {
  return service({
    url: '/cloud/region/regionInfoOnRight', method: "post", data, headers: {"showLoading": true}
  })
}

// 获取区域层级
export function getRegionLevelTreeApi(): Promise<AxiosResponse<IResponseDto<Array<regionInfoDTO>>>> {
  return service({
    url: '/cloud/region/regionLevelTreeOnLeft', method: "post", data: {}, headers: {"showLoading": true}
  })
}

// 创建层级/区域
export function createRegionApi(data: regionInfoDTO): Promise<AxiosResponse<IResponseDto>>{
  return service({
    url: '/cloud/region/create', method: "post", data, headers: {"showLoading": true}
  })
}

// 编辑层级/区域
export function editRegionApi(data: regionInfoDTO): Promise<AxiosResponse<IResponseDto>>{
  return service({
    url: '/cloud/region/update', method: "post", data, headers: {"showLoading": true}
  })
}

// 删除层级/区域
export function delRegionApi(data: delRegionParam): Promise<AxiosResponse<IResponseDto>>{
  return service({
    url: '/cloud/region/deleteRegion', method: "post", data, headers: {"showLoading": true}
  })
}

// 获取点位
export function getPointListApi(data: queryPointParam): Promise<IResponseDto<IResponseArrayDto<pointDTO>>> {
  return service({
    url: '/cloud/region/position/queryPage', method: "post", data, headers: {"showLoading": true}
  })
}

// 创建点位
export function createPositionApi(data: pointDTO): Promise<AxiosResponse<IResponseDto>>{
  return service({
    url: '/cloud/region/position/create', method: "post", data, headers: {"showLoading": true}
  })
}

// 编辑点位
export function editPositionApi(data: pointDTO): Promise<AxiosResponse<IResponseDto>>{
  return service({
    url: '/cloud/region/position/update', method: "post", data, headers: {"showLoading": true}
  })
}

// 删除点位
export function delPositionApi(id: number | undefined): Promise<AxiosResponse<IResponseDto>>{
  return service({
    url: `/cloud/region/position/deleteById/${id}`, method: 'get', data: {}, headers: {"showLoading": true}
  })
}